package com.imooc.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liansen
 * @create 02-22-11:38
 */
@Configuration
public class RabbitmqDeadConfig {

    //交换机名称
    public static final String SMS_EXCHANGE_DEAD = "sms_exchange_dead";

    //死信队列名称
    public static final String SMS_QUEUE_DEAD = "sms_queue_dead";

    //交换机和死信队列的路由键
    public static final String ROUTING_KEY_SMS_DEAD = "dead.sms.display";

    //创建通配符模式交换机
    @Bean("SMS_EXCHANGE_DEAD")
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(SMS_EXCHANGE_DEAD).durable(true).build();
    }

    //创建队列
    @Bean("SMS_QUEUE_DEAD")
    public Queue queue(){
        return QueueBuilder.durable(SMS_QUEUE_DEAD)
                .build();
    }

    //创建交换机与死信队列的绑定关系
    @Bean
    public Binding binding(){
        /**
         * String destination, 目的地
         * DestinationType destinationType, 目的地类型
         * String exchange, String routingKey, 路由键
         * @Nullable Map<String, Object> arguments
         */
        return new Binding(SMS_QUEUE_DEAD, Binding.DestinationType.QUEUE, SMS_EXCHANGE_DEAD, "dead.sms.*", null);
    }

}
